package com.sl.au.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.sl.au.entity.InventoryDetail;
import com.sl.au.repository.InventoryDetailRepository;
import com.sl.au.service.InventoryDetailService;

@Service("InventoryDetailService")
public class InventoryDetailServiceImpl extends BaseServiceImpl implements InventoryDetailService {
    @Autowired
    InventoryDetailRepository inventoryDetailRepository;
	
	@Override
	public InventoryDetailRepository getRepository() {
		return this.inventoryDetailRepository;
	}

	@Override
	public List<InventoryDetail> getInventoryDetail(int start, int length, String key, String orderName, String dir) {
		Page<InventoryDetail> pages = null;
		Pageable pageable = new PageRequest(start / length, length, Sort.Direction.DESC, "createTime");
		if(StringUtils.hasText(key)){
			pages = inventoryDetailRepository.getInventoryDetail(key, pageable);
		}
		else {
			pages = inventoryDetailRepository.findAll(pageable);
		}
		return pages.getContent();
	}

}
